
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<!doctype html>
<html>
<head>
<title>欢迎来到家在曼城</title>
<link href="<c:url value="/resources/front/css/base.css"/>" rel="stylesheet" type="text/css">
<link href="<c:url value="/resources/front/css/style.css"/>" rel="stylesheet" type="text/css">

<style>

</style>

</head>
<body>
<div class="content">
    <div class="w1210 auto rel">
        <div class="register rel">
        	<div class="registerBg0"><img src="<c:url value="/resources/front/images/register_01.jpg"/>" width="1210" height="757"></div>
            <div class="registerBg1"><img src="<c:url value="/resources/front/images/register_02.jpg"/>" width="1210" height="924"></div>
        	<div class="registerMn abs">
            	<ul class="registerUl0">
                	<li class="registerList">
                    	<div class="registerRt"><input type="text" name="nickname" placeholder="不多于8个字"></div>
                    </li>
                    <li class="registerList">
                    	<div class="registerRt"><input type="text" name="username" placeholder="建议邮箱或手机"></div>
                    </li>
                    <li class="registerList r_03">
                    	<div class="registerRt"><input type="password" name="password" placeholder="字母，数字及特殊符号"></div>
                    </li>
                    <li class="registerList r_04">
                    	<div class="registerRt"><input type="password" name="repeatPassword" placeholder="字母，数字及特殊符号"></div>
                    </li>
                    <li class="registerList r_05">
                    	<div class="registerRt dt f0">
                        	<a href="javascript:void(0)" class="detailBtn dib vm"></a>
                            <a href="javascript:void(0)" class="registerBtn dib vm"></a>
                        </div>
                    </li>
                    
                </ul>
                <ul class="registerUl1">
                	<li class="registerList r_06">
                    	<div class="registerRt">
                        	<div class="headPortrait"><img src="<c:url value="/resources/front/images/tu9.png"/>" width="77" height="77"></div>
                        </div>
                    </li>
                    <input type="hidden" name="gender" id="gender">
                	<li class="registerList r_07">
                    	<div class="registerRt rel sex">
                        	<i class="manIcon db abs"></i>
                            <i class="womanIcon dn abs"></i>
                        	<a href="javascript:void(0)" class="manBtn dib abs"></a>
                            <a href="javascript:void(0)" class="womanBtn dib abs"></a>
                        </div>
                    </li>
                    <li class="registerList r_08">
                    	<div class="registerRt"><input type="text" name="name"></div>
                    </li>
                    <li class="registerList r_09">
                    	<div class="registerRt"><input type="text" name="birthday"></div>
                    </li>
                    <li class="registerList r_10">
                    	<div class="registerRt"><input type="text" name="phone"></div>
                    </li>
                    <li class="registerList r_11">
                    	<div class="registerRt"><input type="text" name="school"></div>
                    </li>
                    <li class="registerList r_12">
                    	<div class="registerRt"><input type="text" name="specialty"></div>
                    </li>
                    <li class="registerList r_11">
                    	<div class="registerRt"><input type="text" name="address"></div>
                    </li>
                    <li class="registerList r_12">
                    	<div class="registerRt"><input type="text" name="grade"></div>
                    </li>
                    <li class="registerList r_12">
                    	<div class="registerRt dt f0 pl20">
                            <a href="javascript:void(0)" class="registerBtn dib vm"></a>
                        </div>
                    </li>
                </ul>
            
            </div>
        </div>
    </div>
</div>

</body>
</html>
<script src="<c:url value="/resources/jquery/1.9.1/jquery.min.js" />"></script>
<script src="<c:url value="/resources/front/js/base.js"/>"></script>
<script type="text/javascript">
$(function(){
	var btn = $(".sex a"),
	Icon = $(".sex i"),
	index = 0;
	btn.on("click",function(){
		index = $(this).index()-Icon.length;
		Icon.hide();
		Icon.eq(index).show();
		$("#gender").val(1-index);
	});
	
	$('.registerBg1,.registerUl1').hide();
	
	$('.detailBtn').click(function(){
		$('.registerBg1,.registerUl1').toggle();
	})
	
	$('.registerBtn').click(function(){
		var username = $('input[name=username]').val();
		var nickname = $('input[name=nickname]').val();
		var password = $('input[name=password]').val();
		var repeatPassword = $('input[name=repeatPassword]').val();
		
		var gender = $("#gender").val();
		var name = $('input[name=name]').val();
		var birthday = $('input[name=birthday]').val();
		var phone = $('input[name=phone]').val();
		var school = $('input[name=school]').val();
		var specialty = $('input[name=specialty]').val();
		var address = $('input[name=address]').val();
		var grade = $('input[name=grade]').val();
		
		if(strlen(nickname) > 16){
			alert('昵称不能超过8个汉字(16个字符)！');
			$('input[name=nickname]').focus();
			return;
		}
		
		if(nickname == ''){
			alert('昵称不能为空！');
			$('input[name=nickname]').focus();
			return;
		}
		
		if(username == ''){
			alert('账号不能为空！');
			$('input[name=username]').focus();
			return;
		}
		
		if(password == ''){
			alert('密码不能为空！');
			$('input[name=password]').focus();
			return;
		}
		
		if(password != repeatPassword){
			alert('两次输入密码不一致！');
			$('input[name=repeatPassword]').focus();
			return;
		}
		
		var mydata = '{"type":0,"password":"'  
            + password + '","username":"' +username 
            + '","nickname":"'+nickname
            + '","gender":"'+gender
            + '","name":"'+name
            + '","birthday":"'+birthday
            + '","phone":"'+phone
            + '","school":"'+school
            + '","specialty":"'+specialty
            + '","address":"'+address
            + '","grade":"'+grade+'"}'; 
		
		$.ajax({
			url:'<c:url value="/api/register"/>',
			data:mydata,
			dataType:'json',
			contentType : 'application/json',  
			type:'post',
			success:function(data){
				if(data && data.code){
					alert(data.msg);
					return;
				}else{
					if(data){
						window.location.href = '<c:url value="/"/>'
					}
				}
				
			}
		})
		
	})
})

function strlen(str) {
	var len = 0;
	for (var i = 0; i < str.length; i++) {
		var c = str.charCodeAt(i);
            //单字节加1 
		if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
			len++;
       	}
       	else {
             len += 2;
        }
    }
    return len;
}
	
</script>
